// 2. 封装异步action

import { LoginAPI, LoginformdateType, sendCodeAPI } from '@/api/login';
import { settoken } from '@/utils/storage';
import { AppDispatch } from '..';

/** 发送验证码Action */
export const sendCodeAction = (mobile: string) => {
  return async () => {
    const res = await sendCodeAPI(mobile);
    console.log('res  ----->  ', res);
  };
};
/** 登录Action */
export const LoginAction = (data: LoginformdateType) => {
  return async (dispatch: AppDispatch) => {
    const res = await LoginAPI(data);
    console.log(res.data);
    settoken(res.data);
    //  3. 通过dispatch触发Action
    dispatch({ type: 'user/saveAuth', payload: res.data });
  };
};
